/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProductView.java
 *
 * Created on 2011-feb-22, 15:54:31
 */

package imat;

import javax.swing.JLabel;
import se.chalmers.ait.dat215.project.Product;

/**
 *
 * @author Andreas
 */
public class ProductView extends javax.swing.JPanel {

    private ProductPresenter productPresenter;

    /** Creates new form ProductView */
    public ProductView() {
        initComponents();

        productPresenter = new ProductPresenter(this);
    }

    public void setProduct(Product p) {
        productPresenter.setProduct(p);
    }

    public JLabel getNameLabel() {
        return nameLabel;
    }

    public JLabel getImage() {
        return image;
    }

    public JLabel getPriceLabel() {
        return priceLabel;
    }

    public ImageButton getStarButton() {
        return starButton;
    }

    

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        image = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        priceLabel = new javax.swing.JLabel();
        nameLabel = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        buyButton = new javax.swing.JButton();
        starButton = new imat.ImageButton();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(imat.IMatApp.class).getContext().getResourceMap(ProductView.class);
        setBackground(resourceMap.getColor("Form.background")); // NOI18N
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(250, 100));
        setLayout(new java.awt.GridLayout(1, 2));

        image.setBackground(resourceMap.getColor("image.background")); // NOI18N
        image.setText(resourceMap.getString("image.text")); // NOI18N
        image.setName("image"); // NOI18N
        image.setOpaque(true);
        image.setPreferredSize(new java.awt.Dimension(50, 100));
        add(image);

        jPanel1.setBackground(resourceMap.getColor("jPanel1.background")); // NOI18N
        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel3.setBackground(resourceMap.getColor("jPanel3.background")); // NOI18N
        jPanel3.setName("jPanel3"); // NOI18N
        jPanel3.setPreferredSize(new java.awt.Dimension(125, 50));

        priceLabel.setText(resourceMap.getString("priceLabel.text")); // NOI18N
        priceLabel.setName("priceLabel"); // NOI18N

        nameLabel.setFont(resourceMap.getFont("nameLabel.font")); // NOI18N
        nameLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        nameLabel.setText(resourceMap.getString("nameLabel.text")); // NOI18N
        nameLabel.setName("nameLabel"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(nameLabel)
                    .addComponent(priceLabel))
                .addContainerGap(62, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(nameLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(priceLabel)
                .addContainerGap(14, Short.MAX_VALUE))
        );

        jPanel1.add(jPanel3, java.awt.BorderLayout.CENTER);

        jPanel2.setBackground(resourceMap.getColor("jPanel2.background")); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        buyButton.setText(resourceMap.getString("buyButton.text")); // NOI18N
        buyButton.setToolTipText(resourceMap.getString("buyButton.toolTipText")); // NOI18N
        buyButton.setName("buyButton"); // NOI18N
        buyButton.setPreferredSize(new java.awt.Dimension(73, 30));
        buyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buyButtonActionPerformed(evt);
            }
        });
        jPanel2.add(buyButton);

        starButton.setToolTipText(resourceMap.getString("starButton.toolTipText")); // NOI18N
        starButton.setImageBackground(resourceMap.getString("starButton.imageBackground")); // NOI18N
        starButton.setImageBackgroundDown(resourceMap.getString("starButton.imageBackgroundDown")); // NOI18N
        starButton.setName("starButton"); // NOI18N
        starButton.setPreferredSize(new java.awt.Dimension(37, 37));
        starButton.setText(resourceMap.getString("starButton.text")); // NOI18N
        starButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                starButtonMouseReleased(evt);
            }
        });
        jPanel2.add(starButton);

        jPanel1.add(jPanel2, java.awt.BorderLayout.SOUTH);

        add(jPanel1);
    }// </editor-fold>//GEN-END:initComponents

    private void buyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buyButtonActionPerformed
        productPresenter.addToTrolley();
    }//GEN-LAST:event_buyButtonActionPerformed

    private void starButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_starButtonMouseReleased
        if (starButton.isButtonClicked(evt)) {
            productPresenter.favoriteClicked();
        }
    }//GEN-LAST:event_starButtonMouseReleased


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buyButton;
    private javax.swing.JLabel image;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JLabel priceLabel;
    private imat.ImageButton starButton;
    // End of variables declaration//GEN-END:variables

}
